#pragma once
#include "feDefs.h"

class feVector
{
public:
	feReal *Data;
	int		Size;
	bool	Buffered;


	explicit feVector(feReal *iBuffer)
	{
		Buffered = true;
		Data = iBuffer;
		Size = 0;
	};


	//----------------------------------------------------------------------------------------------------------------------------------
	explicit feVector(int iSize, feReal *iBuffer)
	{
		Buffered = true;
		Data = iBuffer; 
		Size = iSize;
	}


	//----------------------------------------------------------------------------------------------------------------------------------
	explicit feVector(int iSize)
	{
		Buffered = false;
		Data = 0;
		Size = 0;
		Allocate(iSize);		
	}


	//----------------------------------------------------------------------------------------------------------------------------------
	feVector()
	{
		Size = 0;
		Data = NULL;
		Buffered = false;
	}

	
	//----------------------------------------------------------------------------------------------------------------------------------
	void Allocate(int iSize)
	{
		if(iSize == Size) return;

		Free();

		Size = iSize;
		if(Buffered) return;
		
		if(iSize > 0)
			Data = new feReal[Size];
		else
			Data = NULL;
	}


	//----------------------------------------------------------------------------------------------------------------------------------
	void Free()
	{
		if(Data && !Buffered)
		{
			delete [] Data;
			Data = NULL;
		}
		Size = 0;
	}


	//----------------------------------------------------------------------------------------------------------------------------------
	feVector(const feVector &iV)
	{
		Size = iV.Size;
		Data = iV.Data;
	}


	//----------------------------------------------------------------------------------------------------------------------------------
	~feVector()
	{
		Free();
	}


	//----------------------------------------------------------------------------------------------------------------------------------
	int		GetSize()					{ return Size; }
	double operator[](int iIndex) const	{ return Data[iIndex]; }
	double& operator[](int iIndex)		{ return Data[iIndex]; }
};